using Spine.Unity;
using System.Collections.Generic;
using UnityEngine;

public class RandomBoneMovement : MonoBehaviour
{
	private SkeletonAnimation skeletonAnimation;

	private float t;

	private float curveX;

	private float curveY;

	private List<BoneMovementData> boneMovementData = new List<BoneMovementData>();

	private void ParabolicMovement(BoneMovementData bd)
	{
		curveX = bd.velocity * t * bd.angleCos;
		curveY = bd.angleTan * curveX + bd.motion_b * Mathf.Pow(curveX, 2f);
		skeletonAnimation.skeleton.bones.Items[bd.id].x = bd.startPointX - curveX;
		skeletonAnimation.skeleton.bones.Items[bd.id].y = bd.startPointY + curveY;
	}

	private void Start()
	{
		skeletonAnimation = GetComponent<SkeletonAnimation>();
		for (int i = 0; i < skeletonAnimation.skeleton.bones.Count; i++)
		{
			boneMovementData.Add(new BoneMovementData(i, skeletonAnimation.skeleton.bones.Items[i].x, skeletonAnimation.skeleton.bones.Items[i].y));
		}
	}

	private void Update()
	{
		t += Time.deltaTime;
		for (int i = 0; i < boneMovementData.Count; i++)
		{
			ParabolicMovement(boneMovementData[i]);
		}
	}
}
